<template>
  <div class="app-container">

    <!-- 查询和其他操作 -->
    <el-form :inline="true" class="filter-container filter">
      <el-form-item label="客户名称">
        <el-select v-model="listQuery.fsiteNo" :disabled="this.$store.state.user.fsiteLevel==3" clearable filterable placeholder="请选择客户名称">
            <el-option
              v-for="item in fsiteNoBelongOptions"
              :key="item.value"
              :label="item.label"
              :value="item.value"/>
          </el-select>
      </el-form-item>
      <el-form-item label="企业名称">
        <el-input v-model="listQuery.enterpriseName" clearable class="filter-item" style="width: 200px;"
          placeholder="请输入企业名称" />
      </el-form-item>
      <el-form-item label="营业执照">
        <el-input v-model="listQuery.businessLicenseCode" clearable class="filter-item" style="width: 200px;"
          placeholder="请输入所属行业" />
      </el-form-item>
      <el-form-item label="企业性质">
        <el-select v-model="listQuery.industryCategoryCode" clearable filterable class="filter-item"
          placeholder="请选择企业性质">
          <el-option v-for="item in industryCategoryCodeList" :key="item.attributeCode" :label="item.attributeValue"
            :value="Number(item.attributeCode)" />
        </el-select>
      </el-form-item>
      <div>
        <el-form-item>
          <el-button round size="medium" class="filter-item"
            :style="{ background: buttonColor.lookup, color: buttonColor.color }" @click="handleFilter">查找</el-button>
          <el-button round size="medium" class="filter-item"
            :style="{ background: buttonColor.add, color: buttonColor.color }" @click="handleCreate">添加</el-button>

          <el-button round size="medium" class="filter-item"
            :style="{ background: buttonColor.cancellation, color: buttonColor.color }" @click="cancellation">注销</el-button>
          <el-button round size="medium" class="filter-item"
            :style="{ background: buttonColor.reduction, color: buttonColor.color }" @click="reduction">还原</el-button>

        </el-form-item>
      </div>
    </el-form>
    <!-- 查询结果 -->
    <el-table :height="buttonColor.clientHeightTwo" v-loading="listLoading" :data="list" element-loading-text="正在查询中。。。"
      border fit highlight-current-row :header-cell-style="tableColor" @selection-change="handleSelectionChange">
      <el-table-column align="center" :width="buttonColor.operationTwo" label="操作" class-name="small-padding">
        <template slot-scope="scope">
          <div class="operationButton">
            <div :style="{ color: buttonColor.edit, cursor: 'pointer' }" @click="handleUpdate(scope.row)">
              <img src="../../../public/images/edit.png" />
              编辑
            </div>
            <div :style="{ color: buttonColor.delete, cursor: 'pointer' }" @click="handleDelete(scope.row)">
              <img src="../../../public/images/del.png" />
              删除
            </div>
          </div>
        </template>
      </el-table-column>
      <el-table-column type="selection" width="55">
      </el-table-column>
      <el-table-column :width="buttonColor.line" :index="indexMethod" align="center" label="序" type="index" />
      <el-table-column align="left" label="企业名称" prop="enterpriseName" />
      <el-table-column align="left" label="营业执照" prop="businessLicenseCode" />
      <el-table-column align="left" :formatter="industryCategoryCodeFormat" label="企业性质" prop="industryCategoryCode" />
      <el-table-column align="left" :formatter="industryCategoryTypeFormat" label="企业类型" prop="industryCategoryType" />
      <el-table-column width="120" align="left" :formatter="ownedDevelopmentZoneFormat" label="所属开发区"
        prop="ownedDevelopmentZone" />
      <el-table-column align="left" label="联系人" prop="linkMan" />
      <el-table-column width="113" align="left" label="电话" prop="phone" />
      <el-table-column width="113" align="left" label="手机号" prop="mobile" />
      <el-table-column align="left" :width="buttonColor.state" label="状态" prop="auditStatus">
        <template slot-scope="scope">
          <span :style="{ color: buttonColor.statedisable }" v-if="scope.row.auditStatus === 0">{{ scope.row.auditStatus
              |
              statusFilter
          }}</span>
          <span :style="{ color: buttonColor.statestart }" v-else>{{ scope.row.auditStatus | statusFilter }}</span>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit"
      @pagination="getList" />

    <!-- 添加或修改对话框 -->
    <el-dialog width="auto" top="0vh" :close-on-click-modal="false" :visible.sync="dialogFormVisible">
      <template slot="title">
        <div :style="titleColor">{{ textMap[dialogStatus] }}</div>
      </template>
      <el-form ref="dataForm" :rules="rules" :model="dataForm" status-icon label-position="left" label-width="auto">
        <el-row>
          <el-col :span="12">
            <el-form-item class="required" label="企业名称" prop="enterpriseName">
              <el-input v-model="dataForm.enterpriseName" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item class="required" label="营业执照" prop="businessLicenseCode">
              <el-input v-model="dataForm.businessLicenseCode" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item class="required" label="营业执照附件" prop="businessLicenseCodeFile">
              <!-- <el-input v-model="dataForm.businessLicenseCodeFile" /> -->
              <el-upload v-model="dataForm.businessLicenseCodeFile" :show-file-list="false"
                :on-success="handleAvatarSuccess" :before-upload="beforeAvatarUpload" :action="uploadPath"
                :data="businessLicenseCodeFileDaga" class="avatar-uploader">
                <img v-if="dataForm.businessLicenseCodeFile" :src="dataForm.businessLicenseCodeFile" class="avatar"
                  style="width:60px;height:60px">
                <i v-else class="el-icon-plus avatar-uploader-icon" style="font-size:9px"></i>
              </el-upload>

            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item class="required" label="所属行业" prop="industry">
              <el-select v-model="dataForm.industry" clearable filterable class="filter-item" placeholder="请选择所属行业">
                <el-option v-for="item in industryList" :key="item.attributeCode" :label="item.attributeValue"
                  :value="Number(item.attributeCode)" />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item class="required" label="企业性质" prop="industryCategoryCode">
              <el-select v-model="dataForm.industryCategoryCode" clearable filterable class="filter-item"
                placeholder="请选择企业性质">
                <el-option v-for="item in industryCategoryCodeList" :key="item.attributeCode"
                  :label="item.attributeValue" :value="Number(item.attributeCode)" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item class="required" label="企业类型" prop="industryCategoryType">
              <el-select v-model="dataForm.industryCategoryType" clearable filterable class="filter-item"
                placeholder="请选择企业类型">
                <el-option v-for="item in industryCategoryTypeList" :key="item.attributeCode"
                  :label="item.attributeValue" :value="Number(item.attributeCode)" />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item class="required" label="所属省" prop="provinceId">
              <el-select @change="provinceChange" v-model="dataForm.provinceId" clearable filterable class="filter-item"
                placeholder="请选择所属省">
                <el-option v-for="item in provinceIdList" :key="item.id" :label="item.name" :value="item.id" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item class="required" label="所属市" prop="cityId">
              <el-select @change="cityChange" v-model="dataForm.cityId" clearable filterable class="filter-item"
                placeholder="请选择所属市">
                <el-option v-for="item in cityIdList" :key="item.id" :label="item.name" :value="item.id" />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item class="required" label="所属区县" prop="streetId">
              <el-select v-model="dataForm.streetId" clearable filterable class="filter-item" placeholder="请选择所属区县">
                <el-option v-for="item in streetIdList" :key="item.id" :label="item.name" :value="item.id" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item class="required" label="所属开发区" prop="ownedDevelopmentZone">
              <el-select v-model="dataForm.ownedDevelopmentZone" clearable filterable class="filter-item"
                placeholder="请选择所属开发区">
                <el-option v-for="item in ownedDevelopmentZoneList" :key="item.attributeCode"
                  :label="item.attributeValue" :value="Number(item.attributeCode)" />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item class="required" label="地址" prop="address">
              <el-input v-model="dataForm.address" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <img @click="clickMap" style="max-width: 30px;max-height: 30px;margin-top: 3px"
              src="../../../public/images/position.png" alt="">
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="经/纬度" prop="longitude">
              <el-input v-model="dataForm.longitude" />
            </el-form-item>
            <!-- <el-form-item label="纬度" prop="latitude">
          <el-input v-model="dataForm.latitude" />
        </el-form-item> -->
          </el-col>
          <el-col :span="12">
            <el-form-item class="required" label="联系人" prop="linkMan">
              <el-input v-model="dataForm.linkMan" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item class="required" label="电话" prop="phone">
              <el-input v-model="dataForm.phone" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item class="required" label="手机号" prop="mobile">
              <el-input v-model="dataForm.mobile" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item class="required" label="环评附件" prop="eiaAnnexFile">
              <!-- <el-input v-model="dataForm.eiaAnnexFile" /> -->
              <el-upload v-model="dataForm.eiaAnnexFile" :show-file-list="false" :on-success="handleAvatarSuccess1"
                :before-upload="beforeAvatarUpload" :action="uploadPath" :data="eiaAnnexFileData"
                class="avatar-uploader">
                <img v-if="dataForm.eiaAnnexFile" :src="dataForm.eiaAnnexFile" class="avatar"
                  style="width:60px;height:60px">
                <i v-else class="el-icon-plus avatar-uploader-icon" style="font-size:9px"></i>
              </el-upload>
            </el-form-item>
          </el-col>
          <el-col :span="12">
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button round :style="{ background: buttonColor.cancel, color: buttonColor.colorone }"
          @click="dialogFormVisible = false">取消</el-button>
        <el-button round v-if="dialogStatus == 'create'"
          :style="{ background: buttonColor.confirm, color: buttonColor.color }" @click="createData">确定</el-button>
        <el-button round v-else :style="{ background: buttonColor.confirm, color: buttonColor.color }"
          @click="updateData">确定
        </el-button>
      </div>
    </el-dialog>


    <!-- 百度地图 -->
    <el-dialog :close-on-click-modal="false" :visible.sync="dialogFormVisible2" fullscreen width="1200px" height="800px"
      style="width: 100%; height: 80%; padding-top: 0px">
      <template slot="title">
        <div :style="titleColor">百度地图</div>
      </template>
      <div slot="title" align="right" style="margin-top: 10px; margin-right: 30px">
        <el-button round :style="{ background: buttonColor.cancel, color: buttonColor.colorone }"
          @click="dialogFormVisible2 = false">取消</el-button>
        <el-button round :style="{ background: buttonColor.confirm, color: buttonColor.color }" @click="setLatLng">确定
        </el-button>
      </div>
      <cmap :center="dataForm.fsiteParent" :keyword="dataForm.fsiteName" :value="dialogFormVisible2"
        style="margin-top: 0px; width: 100%" @transfer="getPoint" />
    </el-dialog>
  </div>
</template>

<style>
.button-margin {
  margin: 2px 0px;
}

.el-button+.el-button {
  margin-left: 1px;
}
</style>

<script>
import { listenterpriseBasic, createenterpriseBasic, updateenterpriseBasic, deleteenterpriseBasic, setStatus } from '@/api/dangerousWaste/enterpriseBasic'
import { listattributeValue, uploadPath } from '@/api/dangerousWaste/attributeValue'
import { fsiteOptionsByLevel } from '@/api/area'
import { listbaseDistrict } from '@/api/dangerousWaste/baseDistrict'
import Pagination from '@/components/Pagination'
import { tableColor, titleColor, buttonColor } from '@/filters/index'
import moment from 'moment'
import cmap from './baiduMap'

const statusMap = {
  0: '无效',
  1: '有效'
}

export default {
  name: 'WEnterpriseBasic',
  components: { Pagination, cmap },
  filters: {
    statusFilter(type) {
      return statusMap[type]
    }
  },
  data() {
    return {
      fsiteNoBelongOptions: [], // 客户列表
      multipleSelection: [], // 多选列表
      eiaAnnexFileData: {
        "type": '12',
        "value": "环评附件"
      },
      businessLicenseCodeFileDaga: {
        "type": '11',
        "value": "营业执照"
      },
      uploadPath, // 上传图片路径
      industryList: [], //所属行业
      industryCategoryCodeList: [], //企业性质
      industryCategoryTypeList: [], //企业类型
      ownedDevelopmentZoneList: [], //所属开发区
      provinceIdList: [], // 省
      cityIdList: [], // 市
      streetIdList: [], // 市
      dialogFormVisible2: false, // 地图显示
      lat: 0,
      lng: 0,
      tableColor,
      titleColor,
      buttonColor,
      list: null,
      total: 0,
      listLoading: true,
      listQuery: {
        page: 1,
        limit: 20,
        fsiteNo: this.$store.state.user.fsiteNo,
        enterpriseName: undefined,
        businessLicenseCode: undefined,
        industryCategoryCode: undefined,
        sort: 'create_time',
        order: 'desc'
      },
      dataForm: {
        fsiteNo: undefined,
        enterpriseName: undefined,
        industry: undefined,
        industryCategoryCode: undefined,
        industryCategoryType: undefined,
        provinceId: undefined,
        cityId: undefined,
        streetId: undefined,
        ownedDevelopmentZone: undefined,
        businessLicenseCode: undefined,
        businessLicenseCodeFile: undefined,
        enterpriseKind: undefined,
        address: undefined,
        longitude: undefined,
        latitude: undefined,
        linkMan: undefined,
        phone: undefined,
        mobile: undefined,
        status: undefined,
        auditStatus: undefined,
        enterpriseType: undefined,
        eiaAnnexFile: undefined,
        businessStatus: undefined,
        businessStatusTime: undefined,
        yewuName: undefined,
        yewuId: undefined,
        useLimit: undefined,
        openStatus: undefined,
        createAt: undefined,
        createBy: undefined,
        updateAt: undefined,
        updateBy: undefined,
        enterpriseId: null
      },
      dialogFormVisible: false,
      dialogStatus: '',
      textMap: {
        update: '编辑',
        create: '创建'
      },
      rules: {
        enterpriseName: [
          { required: true, message: '企业名称不能为空' },
        ],
        businessLicenseCode: [
          { required: true, message: '营业执照不能为空' },
        ],
        businessLicenseCodeFile: [
          { required: true, message: '营业执照附件不能为空' },
        ],
        industry: [
          { required: true, message: '所属行业不能为空' },
        ],
        industryCategoryCode: [
          { required: true, message: '企业性质不能为空' },
        ],
        industryCategoryType: [
          { required: true, message: '企业类型不能为空' },
        ],
        provinceId: [
          { required: true, message: '所属省不能为空' },
        ],
        cityId: [
          { required: true, message: '所属市不能为空' },
        ],
        streetId: [
          { required: true, message: '所属区县不能为空' },
        ],
        ownedDevelopmentZone: [
          { required: true, message: '所属开发区不能为空' },
        ],
        address: [
          { required: true, message: '地址不能为空' },
        ],
        linkMan: [
          { required: true, message: '联系人不能为空' },
        ],
        phone: [
          { required: true, message: '电话不能为空' },
        ],
        mobile: [
          { required: true, message: '手机号不能为空' },
        ],
        eiaAnnexFile: [
          { required: true, message: '环评附件不能为空' },
        ],
      }
    }
  },
  created() {
    this.getList()
    // 客户列表
    fsiteOptionsByLevel(3)
      .then(response => {
        this.fsiteNoBelongOptions = response.data.data.list
      })
      .catch(() => {
        this.fsiteNoBelongOptions = []
      })
    // 所属行业
    listattributeValue({ itemId: 408 })
      .then(response => {
        console.log('response', response);
        this.industryList = response.data.data.list
      })
      .catch(() => {
        this.industryList = []
      })

    // 企业性质
    listattributeValue({ itemId: -1 })
      .then(response => {
        console.log('response', response);
        this.industryCategoryCodeList = response.data.data.list
      })
      .catch(() => {
        this.industryCategoryCodeList = []
      })

    // 企业类型
    listattributeValue({ itemId: 412 })
      .then(response => {
        console.log('response', response);
        this.industryCategoryTypeList = response.data.data.list
      })
      .catch(() => {
        this.industryCategoryTypeList = []
      })

    // 所属开发区
    listattributeValue({ itemId: 406 })
      .then(response => {
        console.log('response', response);
        this.ownedDevelopmentZoneList = response.data.data.list
      })
      .catch(() => {
        this.ownedDevelopmentZoneList = []
      })
    // 省
    this.getArea(1, 0)

  },
  methods: {
    handleAvatarSuccess(res, file) {
      // this.dataForm.fimage = URL.createObjectURL(file.raw)
      this.dataForm.businessLicenseCodeFile = res.data
      const time = new Date().getTime()
      this.dataForm.businessLicenseCodeFile = `${this.dataForm.businessLicenseCodeFile}?time=${time}`
    },
    handleAvatarSuccess1(res, file) {
      // this.dataForm.fimage = URL.createObjectURL(file.raw)
      this.dataForm.eiaAnnexFile = res.data
      const time = new Date().getTime()
      this.dataForm.eiaAnnexFile = `${this.dataForm.eiaAnnexFile}?time=${time}`
    },

    beforeAvatarUpload(file) {
      const isLt2M = file.size / 1024 / 1024 < 2
      if (!isLt2M) {
        this.$message.error('上传图片大小不能超过 2MB!')
      }
      return isLt2M // isJPG &&
    },

    // 企业性质
    industryCategoryCodeFormat(row, column) {
      if (this.industryCategoryCodeList.length > 0) {
        for (let i = 0; i < this.industryCategoryCodeList.length; i++) {
          if (row.industryCategoryCode == this.industryCategoryCodeList[i].attributeCode) {
            return this.industryCategoryCodeList[i].attributeValue
          }
        }
        return ''
      } else {
        return ''
      }
    },
    // 企业类型
    industryCategoryTypeFormat(row, column) {
      if (this.industryCategoryTypeList.length > 0) {
        for (let i = 0; i < this.industryCategoryTypeList.length; i++) {
          if (row.industryCategoryType == this.industryCategoryTypeList[i].attributeCode) {
            return this.industryCategoryTypeList[i].attributeValue
          }
        }
        return ''
      } else {
        return ''
      }
    },

    // 所属开发区
    ownedDevelopmentZoneFormat(row, column) {
      if (this.ownedDevelopmentZoneList.length > 0) {
        for (let i = 0; i < this.ownedDevelopmentZoneList.length; i++) {
          if (row.ownedDevelopmentZone == this.ownedDevelopmentZoneList[i].attributeCode) {
            return this.ownedDevelopmentZoneList[i].attributeValue
          }
        }
        return ''
      } else {
        return ''
      }
    },

    datetimeFormat(row, column) {
      const date = row[column.property]
      if (date === undefined || date === null) {
        return ''
      }
      return moment(date).format('YYYY-MM-DD HH:mm:ss')
    },
    getArea(level, upid) {
      //  level： 1省 2市 3区
      listbaseDistrict({ limit: -1, page: 1, level: level, upid: upid })
        .then(response => {
          console.log('response', response);
          if (level === 1) {
            this.provinceIdList = response.data.data.list
          } else if (level === 2) {
            this.cityIdList = response.data.data.list
          } else {
            this.streetIdList = response.data.data.list
          }
        })
        .catch(() => {
          this.provinceIdList = []
          this.cityIdList = []
          this.streetIdList = []
        })
    },
    // 改变省
    provinceChange(e) {
      this.dataForm.cityId = ''
      this.cityIdList = []
      this.dataForm.streetId = ''
      this.streetIdList = []
      console.log('eee', e);
      this.getArea(2, e)
    },
    // 市改变
    cityChange(e) {
      console.log('eee', e);
      this.dataForm.streetId = ''
      this.streetIdList = []
      this.getArea(3, e)
    },
    // 地图
    clickMap() {
      // this.resetForm()
      this.dialogFormVisible2 = true
      this.lat = 0
      this.lng = 0
      // this.dataForm.fsiteState = '1'
      // this.$nextTick(() => {
      //   this.$refs['dataForm'].clearValidate()
      // })
    },
    getPoint(point) {
      this.lat = point.lat
      this.lng = point.lng
    },
    setLatLng() {
      this.dialogFormVisible2 = false
      this.dataForm.longitude = this.lat + ',' + this.lng
      this.$refs['dataForm'].validateField('latitude')
      this.$refs['dataForm'].validateField('longitude')
    },
    getList() {
      this.listLoading = true
      listenterpriseBasic(this.listQuery)
        .then(response => {
          this.list = response.data.data.list
          this.total = response.data.data.total
          this.listLoading = false
        })
        .catch(() => {
          this.list = []
          this.total = 0
          this.listLoading = false
        })
    },
    // 注销
    cancellation() {
      if (this.multipleSelection.length > 0) {
        let temp = []
        this.multipleSelection.forEach((item)=>{
          temp.push(item.enterpriseId)
        })
        setStatus({ids: temp, status: 0})
            .then(response => {
              this.$notify.success({
                title: '成功',
                message: '注销成功'
              })
              this.list.forEach(items=>{
                if(temp.includes(items.enterpriseId)){
                  items.auditStatus = 0
                }
              })

            })
            .catch(response => {
              this.$notify.error({
                title: '失败',
                message: response
              })
            })
      } else {
        this.$notify.error({
          title: '失败',
          message: '至少选择一条数据'
        })
      }
    },
    // 还原
    reduction() {
      if (this.multipleSelection.length > 0) {
        let temp = []
        this.multipleSelection.forEach((item)=>{
          temp.push(item.enterpriseId)
        })
        setStatus({ids: temp, status: 1})
            .then(response => {
              this.$notify.success({
                title: '成功',
                message: '还原成功'
              })
              this.list.forEach(items=>{
                if(temp.includes(items.enterpriseId)){
                  items.auditStatus = 1
                }
              })
            })
            .catch(response => {
              this.$notify.error({
                title: '失败',
                message: response
              })
            })
      } else {
        this.$notify.error({
          title: '失败',
          message: '至少选择一条数据'
        })
      }
    },
    // 多选事件
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    handleFilter() {
      this.listQuery.page = 1
      this.getList()
    },
    resetForm() {
      this.dataForm = {
        enterpriseName: undefined,
        industry: undefined,
        industryCategoryCode: undefined,
        industryCategoryType: undefined,
        provinceId: undefined,
        cityId: undefined,
        streetId: undefined,
        ownedDevelopmentZone: undefined,
        businessLicenseCode: undefined,
        businessLicenseCodeFile: undefined,
        enterpriseKind: undefined,
        address: undefined,
        longitude: undefined,
        latitude: undefined,
        linkMan: undefined,
        phone: undefined,
        mobile: undefined,
        status: undefined,
        auditStatus: undefined,
        enterpriseType: undefined,
        eiaAnnexFile: undefined,
        businessStatus: undefined,
        businessStatusTime: undefined,
        yewuName: undefined,
        yewuId: undefined,
        useLimit: undefined,
        openStatus: undefined,
        createAt: undefined,
        createBy: undefined,
        updateAt: undefined,
        updateBy: undefined,
        enterpriseId: null
      }
    },
    handleCreate() {
      this.resetForm()
      this.dialogStatus = 'create'
      this.dialogFormVisible = true
      this.dataForm.industryCategoryType = Number(this.industryCategoryTypeList[0].attributeCode)
      this.dataForm.provinceId = this.provinceIdList[0].id
      this.dataForm.fsiteNo = this.$store.state.user.fsiteNo
      this.getArea(2, this.provinceIdList[0].id)
      this.$nextTick(() => {
        this.$refs['dataForm'].clearValidate()
      })
    },
    createData() {
      this.$refs['dataForm'].validate(valid => {
        if (valid) {
          this.dataForm.auditStatus = 1
          this.dataForm.longitude = this.lng
          this.dataForm.latitude = this.lat
          createenterpriseBasic(this.dataForm)
            .then(response => {
              this.list.unshift(response.data.data)
              this.dialogFormVisible = false
              this.$notify.success({
                title: '成功',
                message: '添加处置企业成功'
              })
            })
            .catch(response => {
              this.$notify.error({
                title: '失败',
                message: response
              })
            })
        }
      })
    },
    handleUpdate(row) {
      this.dataForm = Object.assign({}, row)
      this.dialogStatus = 'update'
      this.dialogFormVisible = true
      this.getArea(2, this.dataForm.provinceId)
      this.getArea(3, this.dataForm.cityId)
      this.dataForm.longitude = this.dataForm.latitude + ',' + this.dataForm.longitude
      this.$nextTick(() => {
        this.$refs['dataForm'].clearValidate()
      })
    },
    updateData() {
      this.$refs['dataForm'].validate(valid => {
        if (valid) {
          this.dataForm.longitude = this.lng
          this.dataForm.latitude = this.lat
          updateenterpriseBasic(this.dataForm, this.$route.query.id)
            .then(() => {
              for (const v of this.list) {
                if (v.enterpriseId === this.dataForm.enterpriseId) {
                  const index = this.list.indexOf(v)
                  this.list.splice(index, 1, this.dataForm)
                  break
                }
              }
              this.dialogFormVisible = false
              this.$notify.success({
                title: '成功',
                message: '更新处置企业成功'
              })
            })
            .catch(response => {
              this.$notify.error({
                title: '失败',
                message: response
              })
            })
        }
      })
    },
    handleDelete(row) {
      this.$confirm('是否要删除处置企业', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        deleteenterpriseBasic(row)
          .then(response => {
            this.$notify.success({
              title: '成功',
              message: '删除处置企业成功'
            })
            const index = this.list.indexOf(row)
            this.list.splice(index, 1)
          })
          .catch(response => {
            this.$notify.error({
              title: '失败',
              message: response
            })
          })
      })
    },
    indexMethod(index) {
      index = index + 1
      return index
    }
  }
}
</script>
